﻿using IBLL;
using IBLL.Dto;
using IDAL;
using Model;
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;

namespace BLL
{
    public class RoomNumBLL : IRoomNumBLL
    {
        public RoomNumBLL(IBase<RoomNumber> db)
        {
            Db = db;
        }

        public IBase<RoomNumber> Db { get; }
        /// <summary>
        /// 添加
        /// </summary>
        /// <param name="t"></param>
        /// <returns></returns>
        public Task<int> AddAsync(RoomNumber t)
        {
           return Db.AddAsync(t);
        }
        /// <summary>
        /// 删除
        /// </summary>
        /// <param name="id"></param>
        /// <returns></returns>
        /// <exception cref="NotImplementedException"></exception>
        public Task<int> DeleteAsync(int id)
        {
           return Db.DeleteAsync(id);   
        }

        public IQueryable<RoomNumber> GetAll()
        {
            return Db.GetAll();
        }
        /// <summary>
        /// 分页
        /// </summary>
        /// <param name="index"></param>
        /// <param name="size"></param>
        /// <param name="roomid"></param>
        /// <param name="name"></param>
        /// <returns></returns>
        public RoomNumPageDto GetRoomNumPage(int index, int size, int roomid, string? name)
        {
            var m = Db.GetAll();
            if (!string.IsNullOrEmpty(name)) 
            {
                m = m.Where(x => x.Name.Contains(name));
            }
            if (roomid > 0) 
            {
                m = m.Where(x => x.RoomId == roomid);
            }
            var c=m.Count();
            var d = m.OrderBy(x => x.Id).Skip((index - 1) * size).Take(size).ToList();
            RoomNumPageDto dto = new RoomNumPageDto();
            dto.Data = d;
            dto.Count = c;
            return dto;
        }
        /// <summary>
        /// 根据编号查一个
        /// </summary>
        /// <param name="id"></param>
        /// <returns></returns>
        public RoomNumber GetValue(int id)
        {
           return Db.GetValue(id);
        }
        /// <summary>
        /// 修改
        /// </summary>
        /// <param name="t"></param>
        /// <returns></returns>
        public Task<int> UpdateAsync(RoomNumber t)
        {
           return Db.UpdateAsync(t);
        }
    }
}
